package gomz.pres.admin;

import gomz.pres.GUIMain;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.border.EmptyBorder;

/**
 * Diese Klasse erstellt das GUI der Kategorieverwaltung in der Verwaltung
 * 
 * @author Dilji
 */

public class GUIACategoryadministration {

	// all the variables for main panels
	private JPanel plCategoryadministration;
	private JPanel plCategoryadministrationNord;
	private JScrollPane spCategoryadministration;

	// all the variables
	private JLabel lbZCategoryadministrationTitle;
	private JScrollPane spZlist;
	private JList liZlist;
	private JButton btZedit;
	private JButton btZdel;
	private JButton btZnew;

	/**
	 * Erstellt das GUI fuer die Kategorieverwaltungs-Sicht
	 * 
	 * @param categorieList fuellt die Kategorieliste
	 * @return gibt das GUI zurueck
	 */
	public JScrollPane getTab(String[] categorieList) {

		// initialize the panels, add to scrollpane and set position
		this.plCategoryadministration = new JPanel();
		this.plCategoryadministrationNord = new JPanel();
		this.spCategoryadministration = new JScrollPane(plCategoryadministrationNord);
		this.plCategoryadministrationNord.setLayout(new BorderLayout());
		this.plCategoryadministrationNord.setBorder(new EmptyBorder((2 * GUIMain.getAbstand()), 0, GUIMain.getAbstand(), 0));
		this.plCategoryadministrationNord.add(plCategoryadministration, BorderLayout.NORTH);

		// set background of main panels
		this.plCategoryadministration.setBackground(Color.WHITE);
		this.plCategoryadministrationNord.setBackground(Color.WHITE);

		// initialize the components of overview
		this.lbZCategoryadministrationTitle = new JLabel("Kategorieverwaltung");
		this.liZlist = new JList(categorieList);
		this.spZlist = new JScrollPane(liZlist);
		this.btZedit = new JButton("Editieren");
		this.btZdel = new JButton("L\u00f6schen");
		this.btZnew = new JButton("Neu");

		// FontSize for title
		this.lbZCategoryadministrationTitle.setFont(GUIMain.getTitlefont());
		this.lbZCategoryadministrationTitle.setForeground(GUIMain.getTitleblue());

		// size of scrollpane from list
		this.spZlist.setPreferredSize(new Dimension(295, 400));
		this.spZlist.setMaximumSize(new Dimension(295, 400));
		this.spZlist.setBorder(GUIMain.getBorderColor());

		// list single selection
		this.liZlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

		// size of buttons
		this.btZedit.setPreferredSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btZedit.setMaximumSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btZdel.setPreferredSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btZdel.setMaximumSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btZnew.setPreferredSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btZnew.setMaximumSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));

		// BOX
		Box btZbox = Box.createVerticalBox();
		btZbox.add(btZedit);
		btZbox.add(Box.createVerticalStrut(GUIMain.getAbstand()));
		btZbox.add(btZdel);
		btZbox.add(Box.createVerticalStrut(GUIMain.getAbstand()));
		btZbox.add(btZnew);

		// scroll speed
		this.spCategoryadministration.getVerticalScrollBar().setUnitIncrement(GUIMain.getScrollspeed());
		this.spZlist.getVerticalScrollBar().setUnitIncrement(GUIMain.getScrollspeed());

		// position of components
		this.plCategoryadministration.setLayout(new GridBagLayout());
		GridBagConstraints cz = new GridBagConstraints();
		cz.fill = GridBagConstraints.HORIZONTAL; // in x-Achse ausfuellen
		cz.insets = new Insets(GUIMain.getAbstand(), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		cz.anchor = GridBagConstraints.NORTHWEST; // Ausrichtung oben

		cz.gridx = 0; // Spalte 1
		cz.gridy = 0; // Zeile 1
		cz.gridwidth = 2;
		plCategoryadministration.add(lbZCategoryadministrationTitle, cz); // label Titel
		cz.gridx = 1; // Spalte 2
		cz.gridy = 0; // Zeile 1
		cz.gridwidth = 1;
		// plCategoryadministration.add(, cz); // Com

		cz.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), 0, (3 * GUIMain.getAbstand()));
		cz.gridx = 0; // Spalte 1
		cz.gridy = 1; // Zeile 2
		plCategoryadministration.add(spZlist, cz); // Liste Kategorien
		cz.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		cz.gridx = 1; // Spalte 2
		cz.gridy = 1; // Zeile 2
		plCategoryadministration.add(btZbox, cz); // Buttons

		return (spCategoryadministration);
	}

	// ********************************************************************************
	// Getters und Setters
	// ********************************************************************************

	public JPanel getPlCategoryadministration() {
		return plCategoryadministration;
	}

	public void setPlCategoryadministration(JPanel plCategoryadministration) {
		this.plCategoryadministration = plCategoryadministration;
	}

	public JPanel getPlCategoryadministrationNord() {
		return plCategoryadministrationNord;
	}

	public void setPlCategoryadministrationNord(JPanel plCategoryadministrationNord) {
		this.plCategoryadministrationNord = plCategoryadministrationNord;
	}

	public JScrollPane getSpCategoryadministration() {
		return spCategoryadministration;
	}

	public void setSpCategoryadministration(JScrollPane spCategoryadministration) {
		this.spCategoryadministration = spCategoryadministration;
	}

	public JLabel getLbZCategoryadministrationTitle() {
		return lbZCategoryadministrationTitle;
	}

	public void setLbZCategoryadministrationTitle(JLabel lbZCategoryadministrationTitle) {
		this.lbZCategoryadministrationTitle = lbZCategoryadministrationTitle;
	}

	public JScrollPane getSpZlist() {
		return spZlist;
	}

	public void setSpZlist(JScrollPane spZlist) {
		this.spZlist = spZlist;
	}

	public JList getLiZlist() {
		return liZlist;
	}

	public void setLiZlist(JList liZlist) {
		this.liZlist = liZlist;
	}

	public JButton getBtZedit() {
		return btZedit;
	}

	public void setBtZedit(JButton btZedit) {
		this.btZedit = btZedit;
	}

	public JButton getBtZdel() {
		return btZdel;
	}

	public void setBtZdel(JButton btZdel) {
		this.btZdel = btZdel;
	}

	public JButton getBtZnew() {
		return btZnew;
	}

	public void setBtZnew(JButton btZnew) {
		this.btZnew = btZnew;
	}

}
